#include "RandomList.h"
#include "common.h"
#include <cstdlib>
#include <cassert>

USING_NS_TEST;

void elloop_test::RandomList::_createList() {
	if (_length == 0) {
		return;
	}
	_list = new int[_length];
	for (size_t index=0; index < _length; ++index) {
		assert(_maxVal > 0 && _maxVal < RAND_MAX);
		_list[index] = rand() % _maxVal;
	}
	_size = _length;
}

int elloop_test::RandomList::operator[]( size_t index ) const
{
	assert(index >= 0);
	return _list[index];
}

int& elloop_test::RandomList::operator[]( size_t index ) {
	assert(index >= 0);
	return _list[index];
}

size_t elloop_test::RandomList::size() const
{
	return _size;
}

size_t elloop_test::RandomList::capacity() const
{
	return _length;
}

elloop_test::RandomList::~RandomList()
{
	if (_list) {
		delete [] _list;
	}
}

elloop_test::RandomList::RandomList( size_t size /*= 0*/, int maxVal /*= 100*/ ) : _size(size), _length(maxVal), _maxVal(maxVal), _list(0) {
	_createList();
}


